package org.datascooter.test.example;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.Transient;

import org.datascooter.annotations.AContainerAttribute;
import org.datascooter.impl.Data;
import org.datascooter.utils.ReferenceInvoker;

public class Location extends Data {

	private static final long serialVersionUID = -4748334175551488110L;
	private Address address;
	private List<Phone> phoneList = new ArrayList<Phone>();
	@AContainerAttribute(mapKeyAttribute = "numberPp")
	private Map<String, Owner> ownerMap = new HashMap<String, Owner>();

	public Location() {
	}

	@AContainerAttribute
	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	@AContainerAttribute
	public List<Phone> getPhoneList() {
		return phoneList;
	}

	public void setPhoneList(List<Phone> phones) {
		this.phoneList = phones;
	}

	public void addPhone(Phone phone) {
		phoneList.add(phone);
	}

	@AContainerAttribute(mapKeyAttribute = "numberPp")
	public Map<String, Owner> getOwnerMap() {
		return ownerMap;
	}

	@SuppressWarnings("unchecked")
	@Transient
	public Map<String, Owner> getOwnerMapLazy() {
		return ReferenceInvoker.invokeMap(this, "ownerMap");
	}

	public void setOwnerMap(Map<String, Owner> map) {
		this.ownerMap = map;
	}

	public void addOwner(Owner owner) {
		ownerMap.put(owner.getNumberPp(), owner);
	}
}
